package com.mj.app.health.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;

import com.google.gson.Gson;
import com.mj.app.health.MyApplication;
import com.mj.app.health.R;
import com.mj.app.health.base.BaseActivity;
import com.mj.app.health.bean.UserBean;
import com.mj.app.health.customer.CountDownProgressView;
import com.mj.app.health.util.SharedPreferanceUtil;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * ========================================
 * *
 * title: LaunchActivity
 * description:
 * *
 * Created by David Hogan on 2018/3/2.
 * ========================================
 */

public class LaunchActivity extends BaseActivity {

    @BindView(R.id.launch_progress)
    CountDownProgressView launchProgress;

    @Override
    protected int setLayoutId() {
        return R.layout.activity_launch;
    }

    private void setProcessListener() {

        launchProgress.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                launchProgress.stop();
                next();
            }
        });
        launchProgress.setProgressListener(new CountDownProgressView.OnProgressListener() {
            @Override
            public void onProgress(int progress) {
                if(progress == 0){

                    launchProgress.stop();
                    next();

                }
            }
        });
    }

    private void next() {
        // 判断是否曾经登录过
        String hasLogin = SharedPreferanceUtil.getSp("UserName","");
        if(TextUtils.isEmpty(hasLogin)){ // 首次登录
            redirectTo(LoginActivity.class);
        }else{
            MyApplication.setUser(new Gson().fromJson(SharedPreferanceUtil.getSp("User",""), UserBean.class));
            redirectTo(MainActivity.class);
        }
        finish();
    }

    @Override
    protected void init() {
        setProcessListener();
        launchProgress.start();
    }
}
